package com.ssh.xml.action;

import java.util.ArrayList;
import java.util.List;

import com.ssh.web.common.BaseAction;
import com.ssh.xml.bean.AutoFactory;
import com.ssh.xml.util.XMLUtil;

public class AutoFactoryAction extends BaseAction {
	private static final long serialVersionUID = 5120232561331406081L;
	private static List<AutoFactory> factory_list = null;

	public String showAutoFactory() {
		String filename = XMLUtil.LOCAL_PATH + "factory_schema.xml";
		List<AutoFactory> list = null;

		if (factory_list == null) {
			list = XMLUtil.getAutoFactoryList(filename);
			factory_list = new ArrayList<AutoFactory>(list);
		} else {
			list = new ArrayList<AutoFactory>(factory_list);
		}

		setPageInfo(list, PAGESIZE);

		int begin = (pageNo -1 ) * PAGESIZE;
		int end = (pageNo * PAGESIZE - 1) > list.size() ? list.size() : (pageNo * PAGESIZE - 1);

		setAttribute("autoFactoryList", list.subList(begin, end));
		setAttribute("currentPage", pageNo);
		setAttribute("pageNo", pageNo);

		return "show";
	}
}
